package android.gpsmessenger;

import java.util.Timer;
import java.util.TimerTask;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.gpsmessenger.location.MyLocationListener;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity
{
	/** Called when the activity is  first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
                
        setContentView(R.layout.activity_main);
        
        android.location.LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        
        //register listener - seems to fix issues in emulator returning null locations
        //TODO: this should start when we hit Record, and we should either let timer query blokcing (and stop this notification)
        //		or set notification interval from user's frequency selection  
        locationManager.requestLocationUpdates(
        		LocationManager.GPS_PROVIDER, 
        		 5 * 1000 ,//5 sec (allows back-end to call getLastKnown...()-- MINIMUM_TIME_BETWEEN_UPDATES, 
        		5,//MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
        		new MyLocationListener()
        );
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
 
        switch (item.getItemId())
        {
	        case R.id.submenu_help_contacts:
	        {
	        	Intent intent = new Intent(this, HelpContactsActivity.class);
	     	    this.startActivity(intent);			           
	            break;
	        }
	        case R.id.submenu_friend_contacts:
	        {
	        	Intent intent = new Intent(this, FriendContactsActivity.class);
	     	    this.startActivity(intent);			           
	            break;
	        }
	        case R.id.submenu_messages:
	        {
	        	Intent intent = new Intent(this, MessagesActivity.class);
	     	    this.startActivity(intent);			           
	            break;
	        }
        }
        
        return(super.onOptionsItemSelected(item));
    }   

}